﻿using GalaSoft.MvvmLight;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;



namespace MVVMLightDemo.ViewModel
{
    [MetadataType(typeof(ValidationViewModel))]
    public class ValidationViewModel : ViewModelBase
    {
        private string telePhone;
        [Required]
        public string TelePhone
        {
            get
            {
                return telePhone;
            }
            set
            {
                telePhone = value;
                this.RaisePropertyChanged("TelePhone");
                if (!Regex.IsMatch(telePhone, @"^\d{4}-?\d{7}|\d{3}-?\d{8}}$"))
                {
                    throw new ApplicationException("不是有效的电话号码！");
                }
            }
        }

        private string email;

        public string Email
        {
            get
            {
                return email;
            }
            set
            {
                email = value;
                this.RaisePropertyChanged(nameof(Email));
            }
        }


        private string name;

        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
                this.RaisePropertyChanged(nameof(Name));
            }
        }
    }
}
